<?php 
session_start();
class Add_examiner extends CI_Controller{
    public function __construct() {
    parent::__construct();
    $this->load->model('Account_m');
    $this->load->helper('url');
    $this->load->helper('form');
    $this->load->library('form_validation');
    $this->load->library('session');
    }
    public function index()
    {        
        $password=$this->input->post('password');
        $name=$this->input->post('name');
        $id_ex=$this->input->post('id');
        $email=$this->input->post('email');
        $adress=$this->input->post('adress');
        $phone=$this->input->post('phone');
        $session_data_sm = $this->session->userdata('logged_in_mg');
	$data['id_mg'] = $session_data_sm['id_mg']; 
        if($this->check_space($id_ex,$password)==1)
        {
            if( $this->Account_m->add_account($id_ex,'examiner')==0 )
                {  
                    echo "<script type='text/javascript'>";	
                    echo "alert ('メールのアドレスまたはIDが存在しました!再入力してお願い致します');";
                    echo "</script>";
                    redirect('manager/add_examiner','refresh');           
                }
             else {
                    $this->Account_m->inser_database_ex($id_ex,$password,$data['id_mg'],$email,$adress,$phone,$name,'examiner');
                    echo "<script type='text/javascript'>";	
                    echo "alert ('採点者の作成が成功');";
                    echo "</script>";
                    redirect('manager','refresh'); 
                    }
        }
        else{                    
                    redirect('manager/add_examiner','refresh');    
            
        }
        }
        public function check_space($a,$b){
        if($a!=NULL && $b!=NULL)
        {
            return 1;
        }
        else
            return 0;
    }
    }
?>
